__author__ = 'aminmahpour'
import os
file = open(os.path.join(os.getcwd(),"Data","consensus_bidir_dnase_50flank.int"), "r")

list_stack=[]
d = {}
i = 0
j =False
start = None
l=[]
for line in file:
    line = line.strip("\n")
    sp = line.split("\t")

    if start is not None:
        if j == False:
            start = int( sp[1])
            j = True

        if start + 1 == int(sp[1]):
            start = int( sp[1])
            l.append(float(sp[4]))
            print float(sp[4])

        else:
            print "XXXXX"
            d.update({i:l})
            i+=1
            l = []
            start =int(sp[1])
            l.append(float(sp[4]))
    else:
        start = int(sp[1])

print (d)

output= open(os.path.join(os.getcwd(),"Export","cons_bidir_dnase.txt"), "w")

for j in d.iterkeys():
    for i in d[j]:
        print i
        output.write("%s\t" % str(i))
    output.write("\n")

output.close()